﻿//Copyright (c) 2010, Andreas Grünwald
//All rights reserved.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yaTDL.Extensions
{
    public static class DateTimeExtensions
    {
        
        public static double ToUnixTime(this DateTime value)
        {
            DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            origin = DateTime.SpecifyKind(origin, DateTimeKind.Utc);
            if (value.Kind == DateTimeKind.Unspecified)
            {
                value = DateTime.SpecifyKind(value, DateTimeKind.Local);
            }
            value = value.ToUniversalTime();
            TimeSpan diff = value - origin;
            return Math.Floor(diff.TotalSeconds);            
        }

    }
}
